package Servlets;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/instructorDashboard")
public class instructorDashboard extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
	{
		
	}


	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
	{
		if(request.getParameter("editInfo")!=null)
		{
			System.out.println("Dashboard->Edit Instructor Info");	
			
			String id= request.getParameter("empid");
			String fname= request.getParameter("fName");
			String lname= request.getParameter("lName");
			String address= request.getParameter("address");
			String city= request.getParameter("city");
			String state= request.getParameter("state");;
			String zipcode= request.getParameter("zipcode");
			String department = request.getParameter("department");
			String location = request.getParameter("location");
			String hours = request.getParameter("officeHours");
			
			request.setAttribute("empid", id);
			request.setAttribute("fname", fname);
			request.setAttribute("lname", lname);
			request.setAttribute("address", address);
			request.setAttribute("city", city);
			request.setAttribute("state", state);
			request.setAttribute("zipcode", zipcode);
			request.setAttribute("department", department);
			request.setAttribute("location", location);
			request.setAttribute("hours", hours);
			
			RequestDispatcher rd=getServletContext().getRequestDispatcher("/View/instructorInfo.jsp");
			rd.forward(request, response);
		}
	else
	{
		if(request.getParameter("courses")!=null)
			{
				System.out.println("Dashboard->View courses.");
				
				String name = request.getParameter("fName")+" "+request.getParameter("lName");
				PrintWriter pw = response.getWriter();
				pw.println("<html>");
				pw.println("<style type='text/css'>	body{ text-align: justify;background-color:orange; font-family: Cambria}		h1{text-align: center; color: black;font-family: Cambria;}		form{font-family: Cambria;}</style>");
				pw.println("<h1>Instructor Courses</h1>");
				pw.println("<br><p>Instructor : "+name+"</p>");
				
				String courses = request.getParameter("courses");
				String[] courselist = courses.split(",");
				ArrayList<String> courselist1 = new ArrayList<String>();
				for(String s:courselist)
					courselist1.add(s.trim());

				pw.println("<fieldset>");
				pw.println("<legend>Courses</legend>");
				for(String s:courselist1)
					{
						pw.println("<label>"+s+"</label><br>");
						pw.println();
					}
				pw.println("</fieldset>");
				pw.println("<INPUT Type='button' VALUE='Back' onClick='history.go(-1);return true;'>");	
			}
	}
	}
}
